<?php get_instance()->view('common/header');?>
<style>
    .content-btn-box,.content-box{margin-top:10px;}
    .container {
        width: 100%;
    }
    .add-tag-btn{line-height: 40px;}
    .option-item {
        margin-bottom: 5px;
        position: relative;
    }
    .del-tag-btn{font-size: 14px;line-height: 36px;display: block;margin-bottom: 4px;}
    .del-tag-btn a{color: red;}
</style>
<div class="page-container home">
    <?php get_instance()->view('common/sidebar');?>
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                    <h3 class="page-title"> <?php echo $title;?></h3>
                    <ul class="page-breadcrumb breadcrumb">
                        <li class="btn-group"> <a class="btn default ml_5 return" href="<?php echo $backUrl;?>"><i class="fa fa-chevron-left"></i> 返回</a> </li>
                        <li> <i class="fa fa-home"></i> <a href="<?php echo $backUrl;?>"> 商品列表  <i class="fa fa-angle-right"></i> </a></li>
                        <li><a href="javascript:void(0);"><?php echo $add ? '添加' : '编辑';?></a></li>
                    </ul>
                    <!-- END PAGE TITLE & BREADCRUMB-->
                </div>
            </div>
            <div class="row">
	            <div class="col-md-12">
	            <div class="tabbable tabbable-custom tabbable-custom-profile">
                        <ul class="nav nav-tabs">
                            <li class="active"><a href="#tab_1_1" data-toggle="tab">基本信息</a></li>
                            <li class=""><a href="#tab_1_2" data-toggle="tab">商品规格</a></li>
                            <li class=""><a href="#tab_1_3" data-toggle="tab">商品详情</a></li>
                        </ul>
                         <form action="<?php echo getUrl('product/home/save')?>" class="form-horizontal" method="post" id="main-form" novalidate="novalidate">
                             <input type="hidden" value="<?php echo $backUrl;?>" class="form-control" name="back_url"/>
							<div class="tab-content">
								<!--收货地址-->
								<div class="tab-pane active" id="tab_1_1">
									<div class="table-actions-wrapper " style="float: right"></div>
									<div class="table-responsive">
										<div class="table-container">
											<!-- table -->
											<div class="form-body">
			                                    <div class="form-group">
			                                        <label class="control-label col-md-2">商品图标<span class="required">*</span></label>
			                                        <div class="col-md-6">
			                                            <div class="fileinput fileinput-new" data-provides="fileinput"><input type="hidden">
			                                                <div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 200px; height: 150px; line-height: 140px;">
			                                                    <img src="<?php echo ! $add ? $info['icon']['og'] : getDefaultImg();?>" />
			                                                </div>
			                                                <div>
			                                                    <span class="btn default btn-file">
			                                                        <span class="fileinput-new">选择图片</span>
			                                                            <span class="fileinput-exists">改变</span>
			                                                        <input name="portrait" type="file">
			                                                    </span>
			                                                    <a href="#" class="btn default fileinput-exists" data-dismiss="fileinput">删除</a>
			                                                </div>
			                                            </div>
			                                            <div class="clearfix margin-top-10">
			                                                <span>
                                    <i class="fa fa-exclamation-triangle"></i>
                                </span>
			                                                	图片格式：gif,png,jpg;大小:2MB
			                                            </div>
			                                        </div>
			                                    </div>
			                                    <div class="form-group">
			                                        <label class="control-label col-md-2">商品名称<span class="required">*</span></label>
			                                        <div class="col-md-6">
			                                            <input class="form-control required" placeholder="输入商品名称" name="name" type="text" value="<?php echo ! $add ? $info['name'] : '';?>">
			                                        </div>
			                                    </div>
			                                    <div class="form-group">
			                                        <label class="control-label col-md-2">商品价格<span class="required">*</span></label>
			                                        <div class="col-md-6">
			                                            <input class="form-control required number" placeholder="输入商品价格" name="goods_price" type="text" value="<?php echo ! $add ? $info['goods_price'] : '';?>">
			                                        </div>
			                                    </div>
			                                    <div class="form-group">
			                                        <label class="control-label col-md-2">市场价格<span class="required">*</span></label>
			                                        <div class="col-md-6">
			                                            <input class="form-control required number" placeholder="输入商品市场价" name="market_price" type="text" value="<?php echo ! $add ? $info['market_price'] : '';?>">
			                                        </div>
			                                    </div>
			                                    <div class="form-group">
			                                        <label class="control-label col-md-2">库存设置<span class="required">*</span></label>
			                                        <div class="col-md-6" style="margin-left: 18px;">
			                                            <div class="radio-list">
			                                                <label class="radio-inline"><input name="is_limited" <?php if( ! $add && $info['is_limited'] == 1):?> checked <?php elseif($add):?> checked <?php endif;?> value="1" type="radio"> 有限库存 </label>
			                                                <label class="radio-inline"><input name="is_limited" <?php if( ! $add && $info['is_limited'] == 2):?> checked<?php endif;?> value="2" type="radio"> 无限库存 </label>
			                                            </div>
			                                        </div>
			                                    </div>
			                                    <div class="form-group" id="quantity">
			                                        <label class="control-label col-md-2">库存<span class="required">*</span></label>
			                                        <div class="col-md-6">
			                                            <input class="form-control required number" name="quantity" type="text" value="<?php echo ! $add ? $info['quantity'] : '0';?>">
			                                        </div>
			                                    </div>
			                                    <!-- 运费  -->
			                                    <div class="form-group">
			                                        <label class="control-label col-md-2">重量<span class="required">*</span></label>
			                                        <div class="col-md-6">
			                                            <input class="form-control required number" placeholder="设置商品重量" name="shipping_fee" type="text" value="<?php echo ! $add ? $info['weight'] : '0';?>">
			                                        </div>
			                                    </div>
                                                <div class="form-group">
                                                    <label class="control-label col-md-2">是否包邮<span class="required">*</span></label>
                                                    <div class="col-md-6" style="margin-left: 18px;">
                                                        <div class="radio-list">
                                                            <label class="radio-inline"><input name="is_free_shipping" <?php if( ! $add && $info['is_free_shipping'] == 1):?> checked <?php elseif($add):?> checked <?php endif;?> value="1" type="radio"> 否 </label>
                                                            <label class="radio-inline"><input name="is_free_shipping" <?php if( ! $add && $info['is_free_shipping'] == 2):?> checked<?php endif;?> value="2" type="radio"> 是 </label>
                                                        </div>
                                                    </div>
                                                </div>
			                                    <!-- 搜索商家 -->
												<div class="form-group">
													<label class="control-label col-md-2">所属商家<span class="required">*</span></label>
													<div class="col-md-6">
														<input class="form-control required" name="merchant_id" type="hidden">
                                                        <?php if (!$changeMerchant):?>
														    <input class="form-control required" name="merchant_name" value="<?php echo $merchant['nickname']?>" readonly>
                                                        <?php endif;?>
													</div>
												</div>
			                                    <!-- 搜索商家 -->
												<div class="form-group">
													<label class="control-label col-md-2">商家分类<span class="required">*</span></label>
													<div class="col-md-6">
														<select class="form-control required" name="category_id">
															<option></option>
														</select>
													</div>
												</div>
			                                    <!-- 轮播图 -->
			                                    <div class="form-group">
										             <label class="control-label col-md-2">轮播图片<span class="required">*</span></label>
										               <div class="col-md-6">
														<!--dom结构部分-->
														<div id="uploader-demo" class="wu-example">
															<!--用来存放item-->
															<div id="fileList" class="uploader-list">
															<?php if( ! $add){ foreach ($info['img'] as $k=>$v){?>
																<div id="WU_<?php echo $k?>"
																	class="file-item thumbnail upload-state-done" style="">
																	<img src="<?php echo $v['xs'];?>" >
																	<div class="info"><?php $tA = explode('/', $v['og']);echo $tA[count($tA)-1]?></div>
																	<div class="info" style="top: 4px; text-indent: 0; right: 4px; left: 0;">
																		<span style="float: right;" class="btna"><i class="fa fa-remove fa-2x"></i></span>
																	</div>
																	<input type="hidden" name="images[WU_<?php echo $k?>]" value="<?php echo $v['og'];?>">
																</div>
																<?php }}?>
															</div>
															<div id="filePicker">选择图片</div>
														</div>
													</div>
										        </div>
										        <!-- 状态 -->
										        <div class="form-group">
			                                        <label class="control-label col-md-2">状态<span class="required">*</span></label>
			                                        <div class="col-md-6" style="margin-left: 18px;">
			                                            <div class="radio-list">
			                                                <label class="radio-inline"><input name="status" <?php if( ! $add && $info['status'] == 2):?> checked <?php elseif($add):?> checked <?php endif;?> value="2" type="radio"> 启用 </label>
			                                                <label class="radio-inline"><input name="status" <?php if( ! $add && $info['status'] == 1):?> checked<?php endif;?> value="1" type="radio"> 禁用 </label>
			                                            </div>
			                                        </div>
			                                    </div>
			                                    <!-- 按钮 -->
			                                   <div class="form-group">
						                            <div class="col-md-offset-2 col-md-9" style="padding-left: 0;">
						                            	<a class="btn blue button-next" href="javascirpt:void(0);" data-toggle="tab" >继续 <i class="m-icon-swapright m-icon-white"></i></a>
						                            </div>
					                            </div>
					                            <script type="text/javascript">
													$(function(){
														$('.button-next').click(function(){
															$('[href="#tab_1_2"]').click();
														});
													});
					                            </script>
			                                  
												<!--  -->
			                                </div>
											<!--  -->
										</div>
									</div>
								</div>
								<!--  -->
								<!--商品规格-->
								<div class="tab-pane" id="tab_1_2">
									<div class="table-actions-wrapper " style="float: right"></div>
									<div class="table-responsive">
										<div class="table-container">
											<!-- 开始 -->
											<div class="form-body" id="property_option">
												<?php if( ! $add){foreach ($property as $k=>$v){?>
													<div class="row option">
														<label class="col-md-2 control-label">标签名称<span class="required">*</span></label>
														<div class="col-md-2">
															<div class="form-group">
																<div class="col-md-12">
																	<input class="form-control required" placeholder="输入标签名称" name="lable[<?php echo $k?>][lable]" type="text" value="<?php echo (! $add) ? $v['lable'] : ''?>">
																	<span class="help-block">
																		<code>输入商品的标签名称</code>
																	</span>
																</div>
															</div>
														</div>
														<div class="col-md-3">
															<div class="form-group">
																<div class="col-md-12">
																	<input type="hidden" id="select2_sample<?php echo $k?>" placeholder="输入属性后回车" name="lable[<?php echo $k?>][value]" class="form-control select2 required" value="<?php echo (! $add) ? implode(',', $v['value']) : ''?>">
																	<span class="help-block">
																		<code>输入属性名称</code>
																	</span>
																</div>
															</div>
														</div>
														<div class="col-md-1">
															<div class="form-group">
																<div class="col-md-12">
																	<div style="margin-top: 10px;">
																	<?php if($k){?>
																		<a href="javascript:void(0);" class="remove_option"><i class="fa fa fa-times"></i>删除</a>
																	<?php }else{?>
																		<a href="javascript:void(0);" class="add-option-btn"><i class="fa fa-plus"></i>添加</a>
																	<?php }?>
																	</div>
																</div>
															</div>
															
														</div>
													</div>	
													<script type="text/javascript">
														$(function(){
													        $("#select2_sample<?php echo $k?>").select2({
													            tags: []
													        });
														})
													</script>
													<?php }}else{?>
													<div class="row">
														<label class="col-md-2 control-label">标签名称<span class="required">*</span></label>
														<div class="col-md-2">
															<div class="form-group">
																<div class="col-md-12">
																	<input class="form-control required" placeholder="输入标签名称" name="lable[0][lable]" type="text" value="">
																	<span class="help-block">
																		<code>输入商品的标签名称</code>
																	</span>
																</div>
															</div>
														</div>
														<div class="col-md-3">
															<div class="form-group">
																<div class="col-md-12">
																	<input type="hidden" id="select2_sample0" placeholder="输入属性后回车" name="lable[0][value]" class="form-control select2 required" value="">
																	<span class="help-block">
																		<code>输入属性名称</code>
																	</span>
																</div>
															</div>
														</div>
														<div class="col-md-1">
															<div class="form-group">
																<div class="col-md-12">
																	<div style="margin-top: 10px;">
																		<a href="javascript:void(0);" class="add-option-btn"><i class="fa fa-plus"></i>添加</a>
																	</div>
																</div>
															</div>
															
														</div>
													</div>	
													<?php }?>
												</div>
												           <!-- 按钮 -->
			                                   <div class="form-group">
						                            <div class="col-md-offset-2 col-md-9" style="padding-left: 0;">
						                            	<a class="btn blue button-next btn_variant" href="javascirpt:void(0);" data-toggle="tab" >继续 <i class="m-icon-swapright m-icon-white"></i></a>
						                            </div>
					                            </div>
					                            <script type="text/javascript">
													$(function(){
														$('.btn_variant').click(function(){
															$('[href="#tab_1_3"]').click();
														});
													});
					                            </script>
			                                  
												<!--  -->
											<!-- 结束 -->
										</div>
									</div>
								</div>
								<!--  -->
								<!--商品详情-->
								<div class="tab-pane" id="tab_1_3">
									<div class="table-actions-wrapper " style="float: right"></div>
									<div class="table-responsive">
										<div class="table-container">
											<div class="form-body">
											<?php if($add){?>
											<!-- 文本 -->
											<div class="form-group option">
												<label class="col-md-2 control-label">文本</label>
												<div class="col-md-4">
													<textarea class="form-control" rows="6" name="detail[1]"></textarea>
												</div>
												<div class="col-lg-1">
			                                           <div style="margin-top: 10px;">
															<a href="javascript:void(0);" class="delete"><i class="fa fa-times"></i>删除</a>
														</div>
			                                       </div>
											</div>
											<!-- 文本结束 -->
											<!-- 图片 -->
											<div class="form-group option">
												<label class="col-md-2 control-label">图片</label>
			                                       <div class="col-lg-4">
			                                           <input type="file" class="show-url" name="2_detail" data-show-remove="false" data-show-loader="true" data-default-file=""/>
			                                       </div>
			                                       <div class="col-lg-1">
			                                           <div style="margin-top: 10px;">
															<a href="javascript:void(0);" class="delete"><i class="fa fa-times"></i>删除</a>
														</div>
			                                       </div>
												   <script>
				                                       $('.show-url').dropify({
				                                           messages: {'default': '点击上传图片','replace': '点击图片上传替换图片','remove':'删除图片','error':'Ooops, something wrong appended.'}}
				                                       ).on('dropify.beforeClear',function(event, element) {
				
				                                           return confirm("Do you really want to delete \"" + element.filename + "\" ?");
				                                       });
				                                   </script>
											</div>
											<?php }else{?>
												<?php foreach ($detail as $k=>$v){?>
													<?php if($v['type'] == 1){?>
														<!-- 文本 -->
														<div class="form-group option">
															<label class="col-md-2 control-label">文本</label>
															<div class="col-md-4">
																<textarea class="form-control" rows="6" name="detail[<?php echo $v['sort']?>]"><?php echo $v['content']?></textarea>
															</div>
															<div class="col-lg-1">
						                                           <div style="margin-top: 10px;">
																		<a href="javascript:void(0);" class="delete"><i class="fa fa-times"></i>删除</a>
																	</div>
						                                       </div>
														</div>
														<!-- 文本结束 -->
													<?php }elseif($v['type'] == 2){?>
														<!-- 图片 -->
														<div class="form-group option">
															<label class="col-md-2 control-label">图片</label>
						                                       <div class="col-lg-4">
						                                       		<input type="hidden" name="imgs[<?php echo $v['sort']?>]" value="<?php echo $v['content'];?>">
						                                           <input type="file" class="show-url" name="<?php echo $v['sort']?>_detail" data-show-remove="false" data-show-loader="true" data-default-file="<?php echo strstr(getImage($v['content'],'og'),'?',true)?>"/>
						                                       </div>
						                                       <div class="col-lg-1">
						                                           <div style="margin-top: 10px;">
																		<a href="javascript:void(0);" class="delete"><i class="fa fa-times"></i>删除</a>
																	</div>
						                                       </div>
															   <script>
							                                       $('.show-url').dropify({
							                                           messages: {'default': '点击上传图片','replace': '点击图片上传替换图片','remove':'删除图片','error':'Ooops, something wrong appended.'}}
							                                       ).on('dropify.beforeClear',function(event, element) {
							
							                                           return confirm("Do you really want to delete \"" + element.filename + "\" ?");
							                                       });
							                                   </script>
														</div>
													<?php }?>
												<?php }?>
											<?php }?>
											<!-- 图片结束 -->
											<div class="form-group" id="add-btn">
												<label class="col-md-2 control-label"></label>
												<div class="col-lg-4">
													<div style="margin-top: 10px;">
														<a href="javascript:void(0);" class="add-text"><i class="fa fa-plus"></i>添加文本</a>
														<a href="javascript:void(0);" class="add-imgs"><i class="fa fa-plus"></i>添加图片</a>
													</div>
												</div>
												
												<script type="text/javascript">
														$(function(){
															var detail_option = <?php echo ($add ? 3 : (isset($detail[count($detail) - 1]['sort']) ? ($detail[count($detail) - 1]['sort'] + 1):1) )?>;
												

												
															  
															$('.add-text').click(function(){
																//文本
																var text = '<div class="form-group option">'
																	text +='	<label class="col-md-2 control-label">文本</label>'
																	text +='	<div class="col-md-4">'
																	text +='		<textarea class="form-control" rows="6" name="detail['+detail_option+']"></textarea>'
																	text +='	</div>'
																	text +='	<div class="col-lg-1">'
																	text +='		<div style="margin-top: 10px;">'
																	text +='			<a href="javascript:void(0);" class="delete"><i class="fa fa-times"></i>删除</a>'
																	text +='		</div>'
																	text +=' 	</div>'
																	text +='</div>'
																		
																$(this).parents('#add-btn').before(text);
																$(this).removeClass('add-text').addClass('add-imgs');
																detail_option++;
															})
															
															$('.add-imgs').click(function(){
																//图片
																var imgs = '<div class="form-group option">'
																	imgs +='	<label class="col-md-2 control-label">图片</label>'
																	imgs +='	<div class="col-lg-4">'
																	imgs +='		<input type="file" class="show-url" name="'+detail_option+'_detail" data-show-remove="false" data-show-loader="true" data-default-file=""/>'
							                                        imgs +='	</div>'
							                                        imgs +='	<div class="col-lg-1">'
							                                        imgs +='		<div style="margin-top: 10px;">'
							                                        imgs +='			<a href="javascript:void(0);" class="delete"><i class="fa fa-times"></i>删除</a>'
							                                        imgs +='		</div>'
							                                        imgs +=' 	</div>'
																	imgs +='</div>'
																		
																$(this).parents('#add-btn').before(imgs);
										                           $('.show-url').dropify({
							                                           messages: {'default': '点击上传图片','replace': '点击图片上传替换图片','remove':'删除图片','error':'Ooops, something wrong appended.'}}
							                                       ).on('dropify.beforeClear',function(event, element) {
							
							                                           return confirm("Do you really want to delete \"" + element.filename + "\" ?");
							                                       });
										                           $(this).addClass('add-text').removeClass('add-imgs');
										                           detail_option++;
															})

															$('.delete').live('click',function(){
																$(this).parents('.option').remove();
															})
														})
												</script>
											</div>

												<!-- 结束 -->
											</div>
											<div class="form-group">
					                            <div class="col-md-offset-2 col-md-9" style="padding-left: 0;">
					                           	 	<input name="id" value="<?php echo ! $add ? $info['id'] : '';?>" type="hidden">
					                            	<button class="btn green"><i class="fa fa-save"></i> 保存</button>
					                            	<a class="btn default seach-btn" href="<?php echo getUrl('member/consumer');?>"><i class="fa fa-chevron-left"></i> 返回</a>
					                            </div>
				                            </div>
										</div>
									</div>
								</div>
								<!--  -->
							</div>
							<!--  -->
                            
						</form>
						<!-- form -->
                </div>
	            </div>
            </div>
        </div>
    </div>
</div>
<div class="content-box" type="0" index="0">
    <script index="0" id="" name="free_content[]" type="text/plain"></script>
</div>
<script>
$(function(){
	var option = <?php echo $add ? 1 : count($property) ?>;
        $("#select2_sample0").select2({
            tags: []
        });
        
		$('.add-option-btn').click(function(){
			if(option >= 5){
				show_message({status:0,message:"最多只能添加"+option+"个"})
				return;
			}
			var html = '<div class="row option">'
				html +='<label class="col-md-2 control-label"><span class="required"></span></label>'
				html +='<div class="col-md-2">'
				html +='<div class="form-group">'
				html +='	<div class="col-md-12">'
				html +='		<input class="form-control required" placeholder="输入标签名称" name="lable['+option+'][lable]" type="text">'
				html +='		<span class="help-block">'
				html +='			<code>输入商品的标签名称</code>'
				html +='		</span>'
				html +='	</div>'
				html +='</div>'
				html +='</div>'
				html +='<div class="col-md-3">'
				html +='	<div class="form-group">'
				html +='		<div class="col-md-12">'
				html +='			<input type="hidden" id="select2_sample'+option+'" placeholder="输入属性后回车" name="lable['+option+'][value]" class="form-control select2 required" value="">'
				html +='			<span class="help-block">'
				html +='				<code>输入属性名称</code>'
				html +='			</span>'
				html +='		</div>'
				html +='	</div>'
				html +='</div>'
				html +='<div class="col-md-1">'
				html +='	<div class="form-group">'
				html +='		<div class="col-md-12">'
				html +='			<div style="margin-top: 10px;">'
				html +='				<a href="javascript:void(0);" class="remove_option"><i class="fa fa fa-times"></i>删除</a>'
				html +='			</div>'
				html +='		</div>'
				html +='	</div>'
				html +='</div>'
				html +='</div>'

				$('#property_option').append(html);	
				$("#select2_sample"+option).select2({
		            tags: []
		        });
				option++;
		})

		$('.remove_option').live('click',function(){
			$(this).parents('.option').remove();
		})
		
	})
</script>
<script type="text/javascript">
    $(function(){
        $.e_validate.init('#main-form', {});
		
        $('select[name="category_id"]').select2({placeholder: '先选择商家,再选择分类'});
        <?php if ($changeMerchant):?>
        //select2 搜索商家
        $('input[name="merchant_id"]').select2({
            closeOnSelect: true,
            placeholder: '搜索商家,输入昵称、电话',
            minimumInputLength: 2,
            ajax: {
                url: "<?php echo getUrl('common/searchUserName')?>",
                dataType: 'json',
                data: function (term, page) {
                    return {
                    	keyword: term
                    };
                },
                results: function (data, page) {
	                console.log(data);
                    return {
                        results: data
                    };
                }
            },
            formatResult: function(movie) {
            	return movie.name;
            },
            formatSelection: function(movie) {
                return movie.name;
            }, 
            dropdownCssClass: "bigdrop",
            escapeMarkup: function (m) {
                return m;
            }
        }).change(function (evt) {
            //根据所选商家 获取分类
            $.get('<?php echo getUrl('common/getCustomList')?>',{merchant_id:(evt.added.id)},function(data){
            	data = eval('('+data+')')
// 	            console.log(data)
				$('select[name="category_id"]').select2("val",""); //设置值为空
            	$('select[name="category_id"]').html('');//清除选项
		        $('select[name="category_id"]').append('<option></option>');//加入默认选项
	            $.each(data,function(index,element){
		            $('select[name="category_id"]').append('<option value="'+element.id+'">'+element.cat_name+'</option>');
		        })
	            
            })
        });
        <?php endif;?>
        <?php if(! $add || !$changeMerchant) {?>
        	//商家设置默认值
	        $('input[name="merchant_id"]').val(<?php echo $info['merchant_id']?>);//设置商家
	        $('input[name="merchant_id"]').parents('.col-md-6')
	        .find('.select2-chosen')
	        .text('<?php echo $merchant['nickname']?>')
	        .parent('a')
	        .removeClass('select2-default');

        	//所属分类 
        	var selections = <?php echo json_encode($category)?>;

	        $.each(selections,function(index,element){
		    	$('select[name="category_id"]').append('<option value="'+element.id+'">'+element.cat_name+'</option>');
		    })
        	$('select[name="category_id"]').select2('val', [<?php echo $info['category_id']?>]);

        	//库存设置
        	if(<?php echo $info['is_limited']?> == 2){
        		$('#quantity').hide();
        	}
        <?php }?>
        
        $('input[name="is_limited"]').click(function(){
			var val = $(this).val()
			if (val == 1){
				$('#quantity').show();
			}else{
				$('#quantity').hide();
			}
        })
    });
</script>
<script>
$(function(){
	
	// 初始化Web Uploader
	var uploader = WebUploader.create({

	    // 选完文件后，是否自动上传。
	    auto: true,

	    // swf文件路径
	    //swf: '<?php echo $this->staticUrl;?>plugins/webuploader/Uploader.swf',

	    // 文件接收服务端。
	    server: '<?php echo getUrl('product/home/uploadImge')?>',

	    // 选择文件的按钮。可选。
	    // 内部根据当前运行是创建，可能是input元素，也可能是flash.
	    pick: '#filePicker',

	    // 只允许选择图片文件。
	    accept: {
	        title: 'Images',
	        extensions: 'gif,jpg,jpeg,bmp,png',
	        mimeTypes: 'image/*'
	    },
		fileVal:'Filedata',
	});

	// 当有文件添加进来的时候
	var input = []
	uploader.on( 'fileQueued', function( file ) {
	    var $li = $(
	            '<div id="' + file.id + '" class="file-item thumbnail" style="">' +
	                '<img>' +
	                '<div class="info">' + file.name + '</div>' +
	                '<div class="info" style="top: 4px;text-indent: 0px;right: 4px;left: none;"><span style="float: right;" class="btna"><i class="fa fa-remove fa-2x"></i></span></div>' +
	                '<input type="hidden" name="images[]" value="">' +
		           '</div>'
	            ),
	    $img = $li.find('img');
	    input[file.id] = $li.find('input');
	    // $list为容器jQuery实例
	    $('#fileList').append( $li );

	    // 创建缩略图
	    // 如果为非图片文件，可以不用调用此方法。
	    // thumbnailWidth x thumbnailHeight 为 100 x 100
	    uploader.makeThumb( file, function( error, src ) {
	        if ( error ) {
	            $img.replaceWith('<span>不能预览</span>');
	            return;
	        }
	        $img.attr( 'src', src );
	    }, 100, 100 );
	});

	// 文件上传过程中创建进度条实时显示。
	uploader.on( 'uploadProgress', function( file, percentage ) {
	    var $li = $( '#'+file.id ),
	        $percent = $li.find('.progress span');
	    // 避免重复创建
	    if ( !$percent.length ) {
	        $percent = $('<p class="progress"><span></span></p>')
	                .appendTo( $li )
	                .find('span');
	    }
	    $percent.css( 'width', percentage * 100 + '%' );
	});

	// 文件上传成功，给item添加成功class, 用样式标记上传成功。
	uploader.on( 'uploadSuccess', function( file,data ) {
	    if(1){
	    	$( '#'+file.id ).addClass('upload-state-done');
		    input[file.id].val(data._raw);
	    }else{
		    var $li = $( '#'+file.id ),
	        $error = $li.find('div.error');
		    // 避免重复创建
		    if ( !$error.length ) {
		        $error = $('<div class="error"></div>').appendTo( $li );
		    }
		    //input[file.id].remove()
		    $error.text('上传失败');
	    }
	    												    
	});

	// 文件上传失败，显示上传出错。
	uploader.on( 'uploadError', function( file ) {
	    var $li = $( '#'+file.id ),
	        $error = $li.find('div.error');

	    // 避免重复创建
	    if ( !$error.length ) {
	        $error = $('<div class="error"></div>').appendTo( $li );
	    }

	    $error.text('上传失败');
	});

	// 完成上传完了，成功或者失败，先删除进度条。
	uploader.on( 'uploadComplete', function( file ) {
	    $( '#'+file.id ).find('.progress').remove();
	});

	//删除图片
	$(".btna").live('click',function(){
		$(this).parents(".file-item").remove();
		uploader.reset();
	})

})

</script>
</body>
</html>